/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#include "stdafx.h"
#include <pgl/core/GDIpHelperRegion.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace pgl
{
void CGDIpHelperRegion::DrawOffScreen(gfxinterface::ELayer eLayer)
{
	using namespace gfxinterface;
	if (!m_pRegion)
		return;

	ASSERT(m_pGfx);

	if(eLayer == LayerBack || eLayer==LayerDisabled)
	{
		// draw background			
		m_pGfx->SetFillColor( 0.815, 0.815, 0.815);
		m_pGfx->DrawRect( m_pGfx->GetWorldLeft(),
				m_pGfx->GetWorldBottom(),
				m_pGfx->GetWorldRight(),
				m_pGfx->GetWorldTop(), 
				RectTypeFilled | RectTypeNoContour);
	}

	// Draw graph
	if (m_bPostRefresh)
	{
		m_pRegion->RefreshView(*m_pGfx, true);
		m_bPostRefresh=false;
	}
	m_pRegion->PlotGfx(*m_pGfx);

	// shareware stuff
#ifdef _PGL_SHAREWARE
	static angle = 35;
	m_pGfx->SetColor(1,0,0,0.7);
	LOGFONT lf;
	lf.lfHeight=static_cast<long>( 
		floor( 
			static_cast<double>(
				m_pGfx->CreateFontSize(
					m_pGfx->GetHDC(),
					static_cast<int>(10+5*sin(angle/180.0*PGL_PI) )
				) 
			) 
		)
	);
	lf.lfWidth=0;
	lf.lfEscapement=0;
	lf.lfOrientation=0;
	lf.lfWeight=FW_NORMAL;
	lf.lfItalic=FALSE;
	lf.lfUnderline=FALSE;
	lf.lfStrikeOut=FALSE;
	lf.lfCharSet=ANSI_CHARSET;
	lf.lfOutPrecision=OUT_TT_PRECIS;
	lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	lf.lfQuality=ANTIALIASED_QUALITY;
	lf.lfPitchAndFamily=FF_DONTCARE|DEFAULT_PITCH;
	_tcscpy( lf.lfFaceName, _T("Verdana"));
	m_pGfx->SetFont(lf);
	CPGLColor col;
	CPGLUtility::ColorMap( CPGLUtility::ColorMapHsv, (angle%90)/90.0, col);
	m_pGfx->SetColor( col.GetRed(), col.GetGreen(), col.GetBlue(), 1);
	m_pGfx->DrawText(m_pGfx->GetWorldLeft()+m_pGfx->GetWorldWidth()/2.0,m_pGfx->GetWorldBottom()+m_pGfx->GetWorldHeight()/2.0,
		_T("PGL"),TextAlignmentCenter,angle);
	angle+=5;
#endif
};

};
